from django.db import models
from django.contrib.auth.models import AbstractUser, Group
import os, datetime, uuid


# Create your models here.


# 用户Model
class UserProfile(AbstractUser):
    user_img = models.ImageField(max_length=100, upload_to="userProfile/images/", verbose_name="用户头像", help_text="用户头像",
                                 blank=True, null=True)
    real_name = models.CharField(max_length=50, null=True, blank=True, verbose_name='真实姓名')
    user_id = models.CharField(max_length=100, verbose_name="工号", unique=True)
    gender = models.CharField(max_length=6, null=True, blank=True, choices=(('男', '男'), ('女', '女')), default='女',
                              verbose_name='性别')
    mobile = models.CharField(max_length=11, null=True, blank=True, verbose_name='手机号')
    role_ids = models.CharField(max_length=255, null=True, blank=True, verbose_name='角色')
    open_id = models.CharField(max_length=50, null=True, blank=True, verbose_name='微信openID')

    is_staff = models.BooleanField(null=False, blank=True, default=True, verbose_name='人员状态',
                                   help_text="指明用户是否可以登录到站点", )
    is_active = models.BooleanField(null=False, blank=True, default=True, verbose_name='用户是否有效',
                                    help_text="指明用户是否被认为是活跃的。以反选代替删除帐号。", )
    is_delete = models.BooleanField(null=False, blank=True, default=False, verbose_name='是否删除')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        verbose_name = '用户'
        verbose_name_plural = verbose_name
        ordering = ('-create_time',)

    def delete(self, using=None, keep_parents=False):
        """重写数据库删除方法实现逻辑删除"""
        self.is_delete = True
        self.save()


